﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class pshop : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Literal_map.Text = RuleCode.Util.getmapurl();
                bind1();
                bind2();
            }
        }

        private void bind1()
        {
            cbuser u = cbuser.Find(" cbuserid = '" + AliApi.appUserId + "'");
            HyperLink_openshop.NavigateUrl = ResolveUrl("~/s.aspx")
                + "?id=" + u.RECID.ToString();
            BizArea a = BizArea.Find("BizAreaName = '" + u.cbUserBizArea.ToString() + "'"
                + " and 区域编码 = '" + u.区域编码.ToString() + "'");
            if (a.p1.ToString().Trim() == "")
            {
                TextBox_1.Visible = false;
                Label1.Visible = false;
            }
            else
            {
                TextBox_1.Visible = true;
                Label1.Visible = true;
                Label1.Text = a.p1.ToString();
            }
            if (a.p2.ToString().Trim() == "")
            {
                TextBox_2.Visible = false;
                Label2.Visible = false;
            }
            else
            {
                TextBox_2.Visible = true;
                Label2.Visible = true;
                Label2.Text = a.p2.ToString();
            }
            if (a.p3.ToString().Trim() == "")
            {
                TextBox_3.Visible = false;
                Label3.Visible = false;
            }
            else
            {
                TextBox_3.Visible = true;
                Label3.Visible = true;
                Label3.Text = a.p3.ToString();
            }
        }
        private void bind2()
        {
            taobaoshop_cat c = taobaoshop_cat.Find(" 1=1");
            DropDownList1.Items.Clear();
            foreach (DataRow item in c.MyTable.Rows)
            {
                DropDownList1.Items.Add(item["taobaoname"].ToString());
            }
            cbshop s = cbshop.Find(" cbuserid = '" + AliApi.appUserId + "'");
            if (s.cbstatus.ToString() == "启用")
            {
                Button11.Enabled = false;
                Button12.Enabled = true;
            }
            else
            {
                Button11.Enabled = true;
                Button12.Enabled = false;
            }
            TextBox3.Text = s.cbshoptitle.ToString();
            c = taobaoshop_cat.Find(" id='"
                + s.taobaoshop_catid.ToString()+"'");
            if (c.Count > 0 && DropDownList1.Items.Count >0)
            {
                DropDownList1.Text = c.taobaoname.ToString();
            }
            TextBox12.Text = s.keyword.ToString();
            TextBox13.Text = s.cbshoptileenglish.ToString();
            TextBox1.Text = s.cbname_yyzz.ToString();
            Fck_jieshao.Value = Server.HtmlDecode(s.cbshopdesc.ToString());
            Fck_gonggao.Value = Server.HtmlDecode(s.shopgonggao.ToString());
            Image1.ImageUrl = s.cbpathlogo.ToString();
            Image2.ImageUrl = s.cbpath0.ToString();
            Image3.ImageUrl = s.cbpath_yyzz.ToString();
            Image4.ImageUrl = s.cbpath_swdjh.ToString();
            //Image3.ImageUrl = s.cbpath1.ToString();
            TextBox_title.Text = s.cbtitle.ToString();
            s.p1.Value = TextBox_1.Text.Trim();
            s.p2.Value = TextBox_2.Text.Trim();
            s.p3.Value = TextBox_3.Text.Trim();
            if (s.NoYes_card.Value == RuleCode.Enum.NoYes.Yes)
            {
                CheckBox_card.Checked = true;
            }
            else
            {
                CheckBox_card.Checked = false;
            }
            if (s.NoYes_sell.Value == RuleCode.Enum.NoYes.Yes)
            {
                CheckBox_sell.Checked = true;
            }
            else
            {
                CheckBox_sell.Checked = false;
            }
            if (s.NoYes_rsms.Value == RuleCode.Enum.NoYes.Yes)
            {
                CheckBox_rsms.Checked = true;
            }
            else
            {
                CheckBox_rsms.Checked = false;
            }
            if (s.NoYes_qthh.Value == RuleCode.Enum.NoYes.Yes)
            {
                this.CheckBox_qtth .Checked = true;
            }
            else
            {
                CheckBox_qtth.Checked = false;
            }
            if (s.NoYes_stwx.Value == RuleCode.Enum.NoYes.Yes)
            {
                this.CheckBox_stwx.Checked = true;
            }
            else
            {
                CheckBox_stwx.Checked = false;
            }
            if (s.NoYes_sdfh.Value == RuleCode.Enum.NoYes.Yes)
            {
                this.CheckBox_sdfh.Checked = true;
            }
            else
            {
                CheckBox_sdfh.Checked = false;
            }
        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.Find(" cbuserid = '" + AliApi.appUserId + "'");
            s.cbshoptitle.Value = TextBox3.Text;

            taobaoshop_cat c = taobaoshop_cat.Find(" taobaoname='"
                + DropDownList1.Text + "'");
            s.taobaoshop_catid.Value = c.id.ToString();
            s.keyword.Value = TextBox12.Text;

            s.cbshoptileenglish.Value = TextBox13.Text;
            s.cbname_yyzz.Value = TextBox1.Text;
            
            s.p1.Value = TextBox_1.Text;
            s.p2.Value = TextBox_2.Text;
            s.p3.Value = TextBox_3.Text;
            if (CheckBox_sell.Checked == true)
            {
                s.NoYes_sell.Value = RuleCode.Enum.NoYes.Yes;
            }
            else
            {
                s.NoYes_sell.Value = RuleCode.Enum.NoYes.No;
            }
            if (CheckBox_card.Checked == true)
            {
                s.NoYes_card.Value = RuleCode.Enum.NoYes.Yes;
            }
            else
            {
                s.NoYes_card.Value = RuleCode.Enum.NoYes.No;
            }
            if (CheckBox_qtth.Checked == true)
            {
                s.NoYes_qthh.Value = RuleCode.Enum.NoYes.Yes;
            }
            else
            {
                s.NoYes_qthh.Value = RuleCode.Enum.NoYes.No;
            }
            if (CheckBox_stwx.Checked == true)
            {
                s.NoYes_stwx.Value = RuleCode.Enum.NoYes.Yes;
            }
            else
            {
                s.NoYes_stwx.Value = RuleCode.Enum.NoYes.No;
            }
            if (CheckBox_sdfh.Checked == true)
            {
                s.NoYes_sdfh.Value = RuleCode.Enum.NoYes.Yes;
            }
            else
            {
                s.NoYes_sdfh.Value = RuleCode.Enum.NoYes.No;
            }
            s.Modify();
       
            MessageBox.Show(this.UpdatePanel1, "修改完毕");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string strImg2 = FileUpload2.FileName.Substring(FileUpload2.FileName.LastIndexOf(".") + 1);
            string time2 = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + strImg2;
            string strFilePth = Server.MapPath(@"~/file/") + time2;
            string linkpth = ResolveUrl(@"~/file/") + time2;
            if (FileUpload2.HasFile)
            {
                FileUpload2.SaveAs(strFilePth);
                cbshop s = cbshop.findorcreate(AliApi.appUserId);
                s.cbpathlogo.Value = linkpth;
                s.Modify();
                bind2();
                MessageBox.Show(this.UpdatePanel3, "上传成功");
                return;
            }
            else
            {
                MessageBox.Show(this.UpdatePanel3, "上传失败");
            }

        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            string strImg2 = FileUpload3.FileName.Substring(FileUpload3.FileName.LastIndexOf(".") + 1);
            string time2 = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + strImg2;
            string strFilePth = Server.MapPath(@"~/file/") + time2;
            string linkpth = ResolveUrl(@"~/file/") + time2;
            if (FileUpload3.HasFile)
            {
                FileUpload3.SaveAs(strFilePth);
                cbshop s = cbshop.findorcreate(AliApi.appUserId);
                s.cbpath0.Value = linkpth;
                s.Modify();
                bind2();
                MessageBox.Show(this.UpdatePanel3, "上传成功");
                return;
            }
            else
            {
                MessageBox.Show(this.UpdatePanel3, "上传失败");
            }

        }
        //protected void Button6_Click(object sender, EventArgs e)
        //{
        //    string strImg2 = FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf(".") + 1);
        //    string time2 = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + strImg2;
        //    string strFilePth = Server.MapPath(@"~/file/") + time2;
        //    string linkpth = ResolveUrl(@"~/file/") + time2;
        //    if (FileUpload1.HasFile)
        //    {
        //        FileUpload1.SaveAs(strFilePth);
        //        cbshop s = cbshop.findorcreate(AliApi.appUserId);
        //        s.cbpath1.Value = linkpth;
        //        s.Modify();
        //        bind2();
        //        MessageBox.Show(this.Page, "上传成功");
        //        return;
        //    }
        //    MessageBox.Show(this.Page, "上传失败");

        //}
        protected void Button4_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            s.cbpathlogo.Value = "";
            s.Modify();
            bind2();
            MessageBox.Show(this.UpdatePanel3, "操作完成");
        }
        protected void Button5_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            s.cbpath0.Value = "";
            s.Modify();
            bind2();
            MessageBox.Show(this.UpdatePanel3, "操作完成");
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            s.cbpath1.Value = "";
            s.Modify();
            bind2();
            MessageBox.Show(this.Page, "操作完成");
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            string strImg2 = FileUpload4.FileName.Substring(FileUpload4.FileName.LastIndexOf(".") + 1);
            string time2 = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + strImg2;
            string strFilePth = Server.MapPath(@"~/file/") + time2;
            string linkpth = ResolveUrl(@"~/file/") + time2;
            if (FileUpload4.HasFile)
            {
                FileUpload4.SaveAs(strFilePth);
                cbshop s = cbshop.findorcreate(AliApi.appUserId);
                s.cbpath_yyzz.Value = linkpth;
                s.Modify();
                bind2();
                MessageBox.Show(this.UpdatePanel4, "上传成功");
                return;
            }
            MessageBox.Show(this.UpdatePanel4, "上传失败");
        }

        protected void Button7_Click1(object sender, EventArgs e)
        {
            string strImg2 = FileUpload5.FileName.Substring(FileUpload5.FileName.LastIndexOf(".") + 1);
            string time2 = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + strImg2;
            string strFilePth = Server.MapPath(@"~/file/") + time2;
            string linkpth = ResolveUrl(@"~/file/") + time2;
            if (FileUpload5.HasFile)
            {
                FileUpload5.SaveAs(strFilePth);
                cbshop s = cbshop.findorcreate(AliApi.appUserId);
                s.cbpath_swdjh.Value = linkpth;
                s.Modify();
                bind2();
                MessageBox.Show(this.UpdatePanel4, "上传成功");
                return;
            }
            MessageBox.Show(this.UpdatePanel4, "上传失败");
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            s.cbpath_yyzz.Value = "";
            s.Modify();
            bind2();
            MessageBox.Show(this.UpdatePanel4, "操作完成");
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            s.cbpath_swdjh.Value = "";
            s.Modify();
            bind2();
            MessageBox.Show(this.UpdatePanel4, "操作完成");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.Find(" cbuserid = '" + AliApi.appUserId + "'");
            s.cbtitle.Value = TextBox_title.Text;
            s.cbshopdesc.Value = Fck_jieshao.Value;
            s.shopgonggao.Value = Fck_gonggao.Value;
            s.Modify();
            MessageBox.Show(this.UpdatePanel2, "修改完毕");
        }

        protected void Button11_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            if (s.cbstatus.ToString() == "" || s.cbstatus.ToString() == "关闭")
            {
                s.cbstatus.Value = "启用";
                s.Modify();
                MessageBox.Show(this.UpdatePanel2, "启用成功");
                Button11.Enabled = false;
                Button12.Enabled = true;
                return;
            }
            
            MessageBox.Show(this.UpdatePanel2, "启用失败");
        }

        protected void Button12_Click(object sender, EventArgs e)
        {
            cbshop s = cbshop.findorcreate(AliApi.appUserId);
            if (s.cbstatus.ToString() == "" || s.cbstatus.ToString() == "启用")
            {
                s.cbstatus.Value = "关闭";
                s.Modify();
                Button11.Enabled = true;
                Button12.Enabled = false;
                MessageBox.Show(this.UpdatePanel2, "启用成功");
                return;
            }

            MessageBox.Show(this.UpdatePanel2, "启用失败");
        }
    }
}
